/*
 *    Copyright 2006-2022 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package me.helllp.dake.generator.sql.config;

import lombok.Getter;
import lombok.Setter;
import me.helllp.dake.generator.meta.PropertyHolder;

import java.util.*;

import static me.helllp.dake.generator.sql.internal.util.StringUtility.*;

@Getter
@Setter
public class TableConfiguration extends PropertyHolder {
    private GeneratedKey generatedKey;

    private String catalog;

    private String schema;

    private String tableName;

    private String remark;

    private String tableType;

    private String domainObjectName;

    private String alias;

    private boolean wildcardEscapingEnabled;

    private boolean delimitIdentifiers;

    private boolean isAllColumnDelimitingEnabled;

    private String mapperName;

    private String sqlProviderName;

    public TableConfiguration() {
        super();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof TableConfiguration)) {
            return false;
        }

        TableConfiguration other = (TableConfiguration) obj;

        return Objects.equals(this.catalog, other.catalog)
                && Objects.equals(this.schema, other.schema)
                && Objects.equals(this.tableName, other.tableName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(catalog, schema, tableName);
    }


    public Optional<GeneratedKey> getGeneratedKey() {
        return Optional.ofNullable(generatedKey);
    }

    @Override
    public String toString() {
        return composeFullyQualifiedTableName(catalog, schema,
                tableName, '.');
    }
}
